package com.cloud.point.jvm;

import java.util.ArrayList;

import lombok.extern.slf4j.Slf4j;

/**
 * gc分区测试
 *
 * @author 24373
 * @version 1.0
 * @date 2024-06-09 22:25
 */
@Slf4j
public class TestGC {
    private static final int _512KB = 512 * 1024;
    private static final int _1MB = 1024 * 1024;
    private static final int _7MB = 7 * 1024 * 1024;
    private static final int _8MB = 8 * 1024 * 1024;

    /**
     * -Xms20M -Xmx20M -Xmn10M -XX:+UseSerialGC -XX:+PrintGCDetails -verbose:gc
     */
    public static void main(String[] args) {
        ArrayList<byte[]> list = new ArrayList<>();
        list.add(new byte[_7MB]);
        list.add(new byte[_512KB]);
        list.add(new byte[_512KB]);
        //大对象在新生代不能容纳时，会直接进入老年代
        new Thread(() -> {
            list.add(new byte[_8MB]);
            list.add(new byte[_8MB]);
        }
        ).start();
        /**
         * 某个线程的OOM报错，不会导致Java进程的结束
         */
        log.info("main线程运行");
        list.add(new byte[_8MB]);


    }

}
